<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
  <title>better-scroll轮播图</title>
  <style>
    body {margin: 0; padding: 0; font-size: 14px;}
    ul, li {margin: 0; padding: 0; list-style: none;}
    .slide-box {
        position: relative;
    }
    .wrapper {
      width: 100vw;
      min-height: 1px;
      overflow: hidden;
    }
    .list {
        white-space: nowrap;
        font-size: 0;
    }
    .list li {
      display: inline-block;
      height: 220px;
      width: 100%;
      text-align: center;
    }
    .list li img {
        display: block;
        margin: 0 auto;
        max-height: 220px;
    }
    /* 导航小点 */
    .dots-wrapper {
        position: absolute;
        bottom: 4px;
        left: 50%;
        transform: translateX(-50%);
    }
    .dots-wrapper .dot {
        display: inline-block;
        margin: 0 4px;
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: #eee;
    }
    .dots-wrapper .dot.active {
        width: 20px;
        border-radius: 5px;
    }
  </style>
  <script src="https://unpkg.com/better-scroll@latest/dist/better-scroll.min.js"></script>
</head>
<body>
    <div class="slide-box">
        <div class="wrapper"> 
            <ul class="list">
                <li><img src="./imgs/1.jpg"></li>
                <li><img src="./imgs/2.jpg"></li>
                <li><img src="./imgs/3.jpg"></li>
                <li><img src="./imgs/4.jpg"></li>
            </ul>
        </div>
        <div class="dots-wrapper">
            <span class="dot active"></span>
            <span class="dot"></span>
            <span class="dot"></span>
            <span class="dot"></span>
        </div>
    </div>  
  <script>
    // better-scroll最基础的使用  
    let wrapper = document.querySelector('.wrapper');
    let list = document.querySelector('.list');
    let slide = BetterScroll.createBScroll(wrapper, {
        scrollX: true, // 当设置为 true 的时候，可以开启横向滚动。
        scrollY: false,
        slide: true,
        useTransition: true,
        momentum: false,
        stopPropagation: true,
        probeType: 3
    });
    slide.on('slideWillChange', (page) => {
        let index = page.pageX;
        let dots = document.querySelectorAll('.dots-wrapper .dot');
        [...dots].forEach(dot => dot.classList.remove('active'));
        dots[index].classList.add('active');
    })
  </script>
</body>
</html>